using System.Windows.Data;

namespace System.Windows.Controls
{
    /// <summary>
    /// Represents a <see cref="TreeGrid"/> column that hosts template-specified content in its cells and support hierarchical data representation
    /// </summary>
    public class HierarchicalTemplateColumn : ManagedTemplateColumn, IHierarchicalColumn
    {
        /// <summary>
        /// Gets or sets the binding for this column, which indicates where to find the collection that represents the next level in the data hierarchy
        /// </summary>
        public Binding ItemsSource { get; set; }

        /// <summary>
        /// Gets or sets value, that indicates will be expanded <see cref="TreeGridItem"/> after creation automaticaly
        /// </summary>
        public bool AutoExpand { get; set; }

        private TreeGrid _parentGrid;

        TreeGrid IHierarchicalColumn.ParentGrid
        {
            get { return _parentGrid; }
            set { _parentGrid = value; }
        }

        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            return _parentGrid.Generate(cell, dataItem, base.GenerateElement(cell, dataItem));
        }

        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
        {
            return _parentGrid.Generate(cell, dataItem, base.GenerateEditingElement(cell, dataItem));
        }
    }
}